<?php 
require_once 'config.inc.php';

$page = $_GET['page'];
$sub_menu = $_GET['sub_menu'];
$style = $_GET['style'];
if(empty($style)){
	$style = 'blue';	
}

$cat = new CmsCat();
$c_list = $cat->selectCat('');

$post = new Post();
$list = $post->selectPost('');

if($_SERVER[REQUEST_METHOD] == 'POST' && !empty($_POST)){
	$safe = new Safe();
	$data = $safe->convertData($_POST);
	if($post->addPost($data)){
		$msg_state = 'success';
		$msg = "添加成功";
	}else{
		$msg_state = 'error';
		$msg = "添加失败";
	}
}elseif ($_GET['action'] == "delete" && is_numeric($_GET['id'])){
	if($post->deletePost($_GET['id'])){
		$msg_state = 'success';
		$msg = "删除成功";
	}else{
		$msg_state = 'error';
		$msg = "删除失败";
	}
}


$tpl = new Template('admin');
$tpl->assign('list',$list);
$tpl->assign('c_list',$c_list);
$tpl->assign('style',$style);

$tpl->assign('msg_state',$msg_state);
$tpl->assign('msg',$msg);

$tpl->subMenu($sub_menu,'post_list','post');
$tpl->page($page,'post');
?>